package com.honour.busserver.backup.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.honour.busserver.backup.base.ResultMsg;
import com.honour.busserver.backup.entity.BusBackFile;
import com.honour.busserver.backup.service.BusBackFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("file")
@CrossOrigin
public class TaskFileController {
    @Autowired
    private BusBackFileService busBackFileService;


    /**
     *  table表格
     * @param page
     * @param size
     * @return
     */
    @GetMapping("page")
    public ResultMsg fileList(Integer page,Integer size){
//        IPage<BusBackFile> info = new Page<>(page, size);
//        return new ResultMsg(true,200,busBackFileService.page(info));
        List<BusBackFile> list = new ArrayList<>();
        list = busBackFileService.fileList();
        return new ResultMsg(true,200,list);
    }

    /**
     *  手动备份
     * @param db
     * @return
     */
    @GetMapping("db")
    public ResultMsg exec(String db) throws IOException {
       return busBackFileService.exec(db);
    }

    /**
     * 删除文件
     */
    @DeleteMapping("deleteFile/{id}")
    public ResultMsg deleteFile(@PathVariable("id")String id){
        return busBackFileService.deleteFile(id);
    }

    /**
     * 判断是否存在数据
     */
    @GetMapping("getFileExist")
    public ResultMsg getFileExist(String id){
        return busBackFileService.getFileExist(id);
    }
}
